#include "priority_queue.h"
#include<array>

void test1()
{
	cyq::priority_queue<int> pq;
	pq.push(1);
	pq.push(2);
	pq.push(3);
	pq.push(4);
	pq.push(5);
	pq.push(6);

	while (!pq.empty())
	{
		cout << pq.top() << " ";
		pq.pop();
	}
	cout << endl;


}


void test2()
{

	cyq::priority_queue<Date, vector<Date>, cyq::Less<Date>> pq;

	pq.push(Date(2024, 7, 29));
	pq.push(Date(2024, 6, 26));
	pq.push(Date(2024, 8, 29));


	while (!pq.empty())
	{
		cout << pq.top() << " ";
		pq.pop();
	}
	cout << endl;

}

void test3()
{
	
	cyq::priority_queue<Date*, vector<Date*>, cyq::LessDate<Date*>> pq;

	pq.push(new Date(2024, 7, 29));
	pq.push(new Date(2024, 6, 26));
	pq.push(new Date(2024, 8, 29));


	while (!pq.empty())
	{
		cout << *pq.top() << " ";
		pq.pop();
	}
	cout << endl;
}

//typename和class
template <class T>
void print(const vector<T>& v)
{
	//不能从没有实例化的类里面取东西
	//编译器会分不清const_iterator 是类型还是静态成员变量(对象)
	//使用typename就可以解决
	// typename就是明确告诉编译器这里是类型，等模板实例化再去找
	typename vector<T>::const_iterator it = v.begin();

	while (it != v.end())
	{
		cout << *it << " ";
		it++;
	}
	cout << endl;

	for (auto e : v)
	{
		cout << e << " ";
	}
}

//非类型模版参数-->静态栈
template<class T,size_t N>  //N实际上是一个常数 在类内不能修改
class stack
{
private:
	T _a1[N];
	T _top;

};

//array
void test4()
{
	array<int, 10> aa;

	//aa[10];
	//array对越界的检查非常严格，越界读和写都会报错
	//普通数组对越界读不会检查，少部分对越界写会检查
}

//函数模板的模板特化
template<class T1,class T2>
void test5(T1 x, T2 y)
{
	cout << "(T1 x, T2 y)" << endl;
}
//全特化
template<>
void test5<int*>(int* x, int* y)
{
	cout << "<int*>(int* x, int* y)" << endl;
}

template<>
void test5<int>(int, int)
{
	cout << "<int>(int, int)" << endl;
}

template<>
void test5(double, int)
{
	cout << "(double, int)" << endl;
}

template<>
void test5(int* x, double* y)
{
	cout << "(int* x, double* y)" << endl;
}

//类模板的特化
void  test6()
{
	cyq::priority_queue<Date*, vector<Date*>, cyq::Less<Date*>> pq;
	pq.push(new Date(2024, 7, 29));
	pq.push(new Date(2024, 6, 26));
	pq.push(new Date(2024, 8, 29));


	while (!pq.empty())
	{
		cout << *pq.top() << " ";
		pq.pop();
	}
	cout << endl;
}

template<class T1, class T2>
class A
{
public:
	void print()
	{
		cout << "<class T1, class T2>" << endl;
	}
private:
};

//类模板的全特化
template<>
class A<double,int>
{
public:
	void print()
	{
		cout << "<double,int>" << endl;
	}
private:
};

//类模板的偏特化
template<class T1>
class A<T1, double>
{
public:
	void print()
	{
		cout << "<T1, double>" << endl;
	}
private:
};

// 类模板的偏特化-->对类型进行限制
template<class T1, class T2>
class A<T1*, T2*>
{
public:
	void print()
	{
		cout << "<T1*, T2*>" << endl;
	}
private:
};

template<class T1, class T2>
class A<T1&, T2&>
{
public:
	void print()
	{
		cout << "<T1&, T2&>" << endl;
	}
private:
};

int main()
{
	test1();
	cout << "-----------------------" << endl;

	test2();
	cout << "-----------------------" << endl;

	test3();
	cout << "-----------------------" << endl;

	//test4();

	//非类型模版参数
	stack<int,10> aa1;
	stack<int, 100> aa2;

	//函数模板的模板特化
	int x = 0;
	double y = 0.0;
	int z = 0;
	test5(x, y);
	test5(x, z);
	test5(y, x);
	test5(&x, &z);
	test5(&x, &y);
	cout << "-----------------------" << endl;

	test6();
	cout << "-----------------------" << endl;


	//类模板的特化
	A<int, int> a1;
	a1.print();

	A<double, int> a2;
	a2.print();

	A<int, double> a3;
	a3.print();

	A<int*, double*> a4;
	a4.print();

	A<int&, double&> a5;
	a5.print();

	A<int*, int*> a6;
	a6.print();

	A<double&, double&> a7;
	a7.print();

	A<double*, int> a8;
	a8.print();

	A<double*, int&> a9;
	a9.print();

	A<double, int&> a10;
	a10.print();

	cout << "-----------------------" << endl;


	return 0;
}